/*
 * @Author: your name
 * @Date: 2021-05-19 17:22:23
 * @LastEditTime: 2021-05-31 20:07:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/home/scheduModal/index.tsx
 */
import { IFormTypeEnum } from '@/components/form/formComponent';
import { FormInstance, Modal } from 'antd';
import HeaderForm from '@/components/form';
import React, { useEffect } from 'react';
import { apply_add_bell, get_store_projects } from '../../../services/pages';
import { globalModel } from '@/pages/globalModel';
import { useRequest } from '@/.umi/plugin-request/request';
import { IForm } from '../../../components/form/formComponent';

interface IProps {
  visible: boolean;
  close: () => void;
  refresh: () => void;
  row?: any;
}

const AddProjectModal = (props: IProps) => {
  const { data, error, loading } = useRequest(() => get_store_projects({}));

  const List: IForm[] = [
    {
      key: 'project_id',
      type: IFormTypeEnum.Select,
      label: '项目名称',
      data: {
        list: data?.results,
        fieldNames: { value: 'project_id', label: 'project_name' },
      },
      rules: [{ required: true }],
    },
  ];

  const onFinish = async (values: any, form: FormInstance) => {
    console.log(props.row, 'props.row==');

    if (props.row?.schedule_id) {
      await apply_add_bell({ ...values, schedule_id: props.row?.schedule_id });
    }
    props.close();
    props.refresh();
  };

  return (
    <Modal
      className="projectModal"
      maskClosable={false}
      visible={props.visible}
      title={props.row?.project_id ? '加钟' : '添加'}
      footer={null}
      onCancel={props.close}
    >
      <HeaderForm
        labelwidth={120}
        layout="horizontal"
        list={List}
        onSubmit={onFinish}
      />
    </Modal>
  );
};
export default AddProjectModal;
